package com.codeczx.notificationdemo;

import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class NotificationBroadcastReceiver extends BroadcastReceiver {

    public static final String TYPE = "type"; //这个type是为了Notification更新信息的，这个不明白的朋友可以去搜搜，很多

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        int type = intent.getIntExtra(TYPE, -1);

//        if (type != -1) {
//            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//            notificationManager.cancel(type);
//        }

        if (action.equals("notification_clicked")) {
            //处理点击事件
            Log.i("codeczx","notification_clicked");
            context.stopService(new Intent(context,DownloadService.class));
            context.startActivity(new Intent(context,Main2Activity.class));
        }

        if (action.equals("notification_cancelled")) {
            //处理滑动清除和点击删除事件
            Log.i("codeczx","notification_cancelled");
        }
    }
}
